<?php
$relPath='./pinc/';
require_once $relPath."dpinit.php";
require_once $relPath."dp_main.inc";

$tatext         = Arg("tatext");
$islistlocales  = IsArg("listlocales");
$islistwords    = IsArg("listwords");
$locale         = setlocale(LC_CTYPE, null);
$setlocale      = Arg("setlocale", $locale);
dump($setlocale,"  ".$locale);

if($islistlocales) {
    $divout = shell_exec('locale -a');
    $divout = dumpstr($divout);
}
else if($islistwords) {
    setlocale(LC_CTYPE , $locale);
    $aout = t_t_w($tatext);
    $divout = dumpstr($aout);
}
else {
    $divout = "";
}

// corinne
// $projectid      = ArgProjectId("110930002");
// $langcode       = "fr";
// $pagename       = "";

// $projectid = ArgProjectId();
// $pagename  = ArgPageName();
// $langcode  = ArgLangCode();

// Aus Italien
// $projectid = ArgProjectId("111001002");
// $langcode = "de"
// $pagename = ArgPageName("145");

// $project = new DpProject($projectid);

echo "<!doctype html>
<head>
<title></title>
<body>
<form name='frm' id='frm' method='POST' action=''>
Set locale: <input type='text' name='setlocale' value='$setlocale' />
<input type='submit' name='listlocales' id='listlocales'
    value='List system locales'>
<input type='submit' name='listwords' id='listwords' 
value='List words'>
<br>
<div name='divout' id='divout' style='float: left; margin: 0 2em;'>
$divout
</div>
<textarea name='tatext' id='tatext' rows='30' cols='100' style='float: left;'>
$tatext
</textarea>
</form>
</body></html>\n";


function t_t_w($str) {
    define("NOCHARS", "[^\\p{L}]");
    $ptn = "/".NOCHARS."+/u";
    $ary = array_unique(array_diff(preg_split($ptn, $str), array("")));
    natsort($ary);
    return $ary;
}


?>
